package cc.cc4414.cc02.system.entity;

import java.util.Collection;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Transient;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import lombok.Data;

/**
 * 用户
 * 
 * @author cc 2018年4月22日
 */
@Entity
@Data
public class User implements UserDetails {

	private static final long serialVersionUID = -4688370424662751235L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	/** 用户名 */
	private String username;

	/** 密码 */
	private String password;

	/** 创建时间 */
	private Date createTime;

	/** 修改时间 */
	private Date updateTime;

	/** 状态码：0为正常，1为删除 */
	private Integer state;

	/** 昵称 */
	private String nickname;

	/** 手机号 */
	private String mobile;

	/** 邮箱 */
	private String email;

	/** 新增用户时的ip */
	private String ip;

	/**
	 * 权限集合，不持久化到数据库
	 */
	@Transient
	private Collection<? extends GrantedAuthority> authorities;

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}
